import java.util.Arrays;

public class test {
    public static void duplicateZeros(int[] arr) {
        int cur = 0;
        int dest = -1;
        while (dest < arr.length - 1) {
            if (arr[cur] == 0) {
                dest += 2;
            } else {
                dest++;
            }
            if (dest >= arr.length - 1) {
                break;
            }
            cur++;
        }
        if (arr[cur] == 0 ) {
            dest--;
            arr[dest] = 0;
            dest--;
            cur--;
        }
        while (cur > 0) {
            if (arr[cur] == 0) {
                arr[dest] = 0;
                dest--;
                arr[dest] = 0;
                cur--;
                dest--;
            } else {
                arr[dest] = arr[cur];
                cur--;
                dest--;
            }
        }
        System.out.println(Arrays.toString(arr));
    }
    public static void main(String[] args) {
        int[] arr = new int[] {1,0,7,2,4,3,1,0,2,6};
        duplicateZeros(arr);
    }
}
